﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class LoaiVanBangRepository : GenericRepository<MainDataContainer>
    {
        public LoaiVanBangRepository(string connectionString) : base(connectionString, "MainData") { }
        public LoaiVanBangRepository(MainDataContainer context) : base(context) { }

        public LoaiVanBang GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<LoaiVanBang>(d => d.ID == IDFilter);
            return query;
        }

        public LoaiVanBang GetSingleByTen(string TenFilter)
        {
            var query = this.GetFirst<LoaiVanBang>(d => d.TenGoi == TenFilter);
            return query;
        }

        public IEnumerable<LoaiVanBang> GetAll()
        {
            var query = this.GetAll<LoaiVanBang>();
            return query;
        }

        //public IEnumerable<LoaiVanBang> GetAllBySinhVienID(int SinhVienIDFilter)
        //{ 
            
        //    //var quey = this.GetAll<LoaiVanBang>().Where(d => d.VanBangDuocNhan.Where(a => a.SinhVienID == SinhVienIDFilter);
        //}

        public void Save(LoaiVanBang obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<LoaiVanBang>(obj);
                }
                else
                {
                    this.Add<LoaiVanBang>(obj);
                }
            }
            catch { }
        }

        public void Remove(LoaiVanBang obj)
        {
            this.Delete<LoaiVanBang>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<LoaiVanBang>(v => v.ID == IDFilter);
            this.Delete<LoaiVanBang>(obj);
        }
    }
}
